<template>
	<view class="container bg-white">


		<view class="content">
			<view class="top">
				<image src="/static/images/logo.png" class="logo" mode="widthFix"></image>
				<u-form :model="form" ref="uForm" :error-type="['toast']">
					<u-form-item prop="username">
						<view class="cell">
							<view class="name">账号</view>
							<view class="input-box">
								<input type="text" v-model="form.username" placeholder="请输入账号" class="ipt"
									placeholder-class="hold" />
							</view>
						</view>
					</u-form-item>
					<u-form-item prop="password">
						<view class="cell">
							<view class="name">密码</view>
							<view class="input-box">
								<input type="password" v-model="form.password" placeholder="请输入密码" class="ipt"
									placeholder-class="hold" />
							</view>
						</view>
					</u-form-item>
				</u-form>

				<!-- <view class="cell">
					<view class="name">短信验证码</view>
					<view class="input-box">
						<input type="number" v-model="code" placeholder="请输入验证码" class="ipt" placeholder-class="hold"
							@blur="handleInputCheck" />
						<view class="code" @click="sendCode" v-if="count === 60">获取验证码</view>
						<view class="code" v-else><text>{{ count }}</text>秒重新获取</view>
					</view>
				</view> -->
				<!-- <view class="agree">
					登录即代表同意
					<text class="a">《用户协议》</text>
					和
					<text class="a">《隐私政策》</text>
				</view> -->
				<button class="submit" @click="submit">登录</button>
			</view>

		</view>
		<!--  -->
	</view>
</template>

<script>
	import md5 from '@/utils/md5.js'
	export default {
		data() {
			return {
				form: {
					username: '',
					password: ''
				},
			};
		},
		onReady() {
			var rule = {
				username: [{
					required: true,
					message: '请输入姓名',
					trigger: ['blur', 'change']
				}],
				password: [{
					required: true,
					message: '请输入密码',
					trigger: ['blur', 'change']
				}]
			}

			this.$refs.uForm.setRules(rule);
		},
		methods: {
			submit() {

				var that = this
				this.$refs.uForm.validate(valid => {
					if (valid) {

						this.$http.post("login", this.form).then((res) => {

							uni.setStorageSync("accessToken", res.data)

							that.$u.func.setToken(res.data)
							console.log('get_token');

						}).catch((res) => {


							uni.showToast({
								title: res.msg,
								icon: "none"
							})


						}).then((res) => {

							this.$http.get("getInfo", {
								// openid: openid
							}).then(function(res) {

								that.$u.func.login(res.data)

							})

						});
						console.log('验证通过');
					} else {
						uni.showToast({
							title: res.msg,
							icon: "none"
						})
					}
				});


				// this.$u.api.token(this.tenantId, this.username, md5(this.password)).then(data => {
				// 	this.$u.func.login(data)
				// }).catch(err => {
				// 	console.log(err)
				// 	this.$u.func.showToast({
				// 		title: '用户名或密码错误',
				// 	})
				// })
			}
		}
	};
</script>

<style lang="scss">
	.container {
		min-height: 100vh;
		overflow: hidden;

		.set-icon {
			vertical-align: middle;
			width: 41rpx;
			height: auto;
			margin-right: 35rpx;
		}
	}

	.content {
		display: flex;
		flex-direction: column;
		justify-content: space-around;
		align-items: center;

		height: 90vh;
		width: 100%;

		.top {
			width: 100%;
		}

		.logo {
			display: block;
			width: 281rpx;
			height: auto;
			margin: 0 auto 120rpx;
		}

		.cell {
			width: 100%;
			padding: 0 85rpx;
			box-sizing: border-box;
			margin-top: 36rpx;

			.name {
				font-size: 22rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #3e4a59;
				line-height: 30rpx;
				opacity: 0.72;
			}

			.input-box {
				padding: 30rpx 0;
				border-bottom: 2rpx solid #f6f6f6;
				display: flex;
				align-items: center;

				.code {
					font-size: 22rpx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #0d0d0d;
					line-height: 30rpx;

					text {
						color: #14b9c8;
					}
				}

				.ipt {
					flex: 1;
					// height: 24rpx;
					font-size: 24rpx;
				}

				.hold {
					font-size: 26rpx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #3e4a59;
					line-height: 30px;
					opacity: 0.45;
				}
			}
		}

		.agree {
			margin: 27rpx 95rpx 0;
			font-size: 22rpx;
			font-family: Adobe Heiti Std;
			font-weight: normal;
			color: #cacaca;
			line-height: 34rpx;

			.a {
				color: #000000;
			}
		}

		.submit {
			margin: 60rpx 90rpx 0;
			border: none;
			width: 572rpx;
			height: 86rpx;
			line-height: 86rpx;
			box-sizing: border-box;
			border-radius: 15rpx;
			background-color: #14b9c8;
			color: #ffffff;

			&::after {
				content: none;
			}

			&::before {
				content: none;
			}

			&[disabled='true'] {
				background: #e4e4e4;
				font-size: 36rpx;
				font-family: Source Han Sans CN;
				font-weight: 500;
				color: #ffffff;
			}
		}

		.tip {
			margin-top: 30rpx;
			text-align: center;
			font-size: 22rpx;
			font-family: Adobe Heiti Std;
			font-weight: normal;
			color: #cacaca;
			line-height: 34rpx;
		}

		.change {
			margin-top: 20rpx;
			text-align: center;
			font-size: 22rpx;
			font-family: Adobe Heiti Std;
			font-weight: normal;
			color: #14b9c8;
			line-height: 34rpx;
		}

		.tag {
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 22rpx;
			font-family: Adobe Heiti Std;
			font-weight: normal;
			color: #9f9f9f;
			line-height: 34rpx;

			&::before {
				content: '';
				display: block;
				width: 160rpx;
				height: 1px;
				background: #d8d8d8;
				opacity: 0.86;
			}

			&::after {
				content: '';
				display: block;
				width: 160rpx;
				height: 1px;
				background: #d8d8d8;
				opacity: 0.86;
			}
		}

		.chat-arr {
			margin-top: 50rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.icon {
				width: 73rpx;
				height: 73rpx;
			}
		}
	}
</style>
